package com.shop.trade.atom.atomsvc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.common.model.InputBean;
import com.shop.common.model.ServiceBean;
import com.shop.common.model.param.trade.OrderCommentInput;
import com.shop.common.model.result.trade.OrderCommentOutput;
import com.shop.common.tmpl.BaseService;
import com.shop.trade.atom.atomsvc.IOrderCommentAtomSvc;
import com.shop.trade.atom.dao.OrderCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年04月16日  3:23
 */
@Service
public class OrderCommentAtom extends BaseService implements IOrderCommentAtomSvc {
    @Autowired
    OrderCommentMapper orderCommentMapper;

    @Override
    public ServiceBean<Integer> addComment(OrderCommentInput input) {
        int i = orderCommentMapper.insertSelective(input);
        if (i > 0) {
            return resultData(input.getId());
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<Integer> modComment(OrderCommentInput input) {
        int i = orderCommentMapper.updateByPrimaryKeySelective(input);
        if (i > 0) {
            return resultData(i);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<Integer> delComment(Integer id) {
        int i = orderCommentMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            return resultData(i);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<OrderCommentOutput> qryOrderComment(OrderCommentInput input) {
        OrderCommentOutput orderCommentOutput = orderCommentMapper.selectByPrimaryKey(input.getId());
        if (orderCommentOutput != null) {
            return resultData(orderCommentOutput);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<List<OrderCommentOutput>> qryOrderComments(OrderCommentInput input) {
        List<OrderCommentOutput> list = orderCommentMapper.qryOrderComments(input);
        if (list != null && list.size() > 0) {
            return resultData(list);
        }
        return resultFailed();
    }

    @Override
    public OrderCommentOutput qryCommentCount(OrderCommentInput input) {
        return orderCommentMapper.qryCommentCount(input);
    }

    @Override
    public ServiceBean<List<OrderCommentOutput>> qryOrderComments4P(InputBean<OrderCommentInput> input) {
        PageHelper.startPage(input.getIndex(),input.getPageSize());
        List<OrderCommentOutput> list = orderCommentMapper.qryOrderComments(input.getParam());
        if (list == null || list.size() == 0) {
            return resultFailed();
        }
        PageInfo<OrderCommentOutput> pageInfo = new PageInfo<>(list);
        ServiceBean<List<OrderCommentOutput>> serviceBean = new ServiceBean<>();
        serviceBean.setData(pageInfo.getList());
        serviceBean.setMaxSize(pageInfo.getTotal());
        return serviceBean;
    }
}
